package com.example.coinhelper.utils;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Locale;

public class TimeUtility {

    public static boolean isInCurrentMonth(String timeStr) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm");
        LocalDateTime givenTime = LocalDateTime.parse(timeStr, formatter);
        LocalDateTime currentTime = LocalDateTime.now();

        return givenTime.getMonth() == currentTime.getMonth() &&
                givenTime.getYear() == currentTime.getYear();
    }

    public static boolean isToday(String timeStr) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm");
        LocalDateTime givenTime = LocalDateTime.parse(timeStr, formatter);
        LocalDate givenDate = givenTime.toLocalDate();
        LocalDate currentDate = LocalDate.now();
        return givenDate.isEqual(currentDate);
    }
    public static String getCurrentLocalTime() {
        // 获取当前时间
        Date currentDate = new Date();
        // 指定日期格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("MM月dd日 HH时mm分", Locale.getDefault());
        // 格式化时间并返回格式化后的时间字符串
        return dateFormat.format(currentDate);
    }

}
